import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import { registerApplication, start } from "single-spa";

Vue.config.productionTip = false;

const loadScript = async (url) => {
  return new Promise((resolve, reject) => {
    const script = document.createElement("script");
    script.src = url;
    script.onload = resolve;
    script.error = reject;
    document.head.appendChild(script);
  });
};

registerApplication("childVueApp", async () => {
  await loadScript("http://localhost:10086/js/chunk-vendors.js");
  await loadScript("http://localhost:10086/js/app.js");
  return window.ChildVueLib;
}, location => location.pathname.startsWith('/childVue'));
start();

new Vue({
  router,
  render: (h) => h(App),
}).$mount("#app");
